{include file="{APP_PPDP}/home/header.html"}
<!--主体-->
<div class="content">
    <!--左侧导航-->
    {include file="{APP_PPDP}/home/menuLeft.html"}
    <!--右侧内容-->

    <div class="content-right fl">
        <div class="summary fl">
            <h3 class="summary-header">全部订单</h3>
        </div>
        <div class="order-content-wrap">
            <div id="show">
            {if $rows neq 0}
           {foreach $rows as $key=>$val}
            <div class="order-content">
                <div class="order-meal">
                    <table>
                        <thead>
                        <tr>
                            <th colspan="3">
                                <a href='/shop/{$val.shopId}'  class="shop-name">{$val.shopName}</a>
                                <p class="shop-info">
                                    <span class="phone-icon"></span>商家电话：{$val.shopPhone}
                                </p>
                            </th>
                        </tr>
                        </thead>
                        <tbody>

                        {foreach $val['items'] as $obj}
                        <tr>
                            <td>{$obj.name}</td>
                            <td>{$obj.count}</td>
                            <td class="text-right">￥{$obj.price}</td>
                        </tr>
                        {/foreach}

                        </tbody>
                    </table>
                    <div class="order-price">
                        总价：<span class="ft-red">￥{$val.price}</span>
                    </div>
                    <div class="order-delivery">
                        <div class="receive-info">
                            <span>订单编号：{$val.orderId}</span>
                            <span>送餐地址：{$val.orderAddress}</span>
                            <span>联系人：{$val.orderName}</span>
                            <span>电话：{$val.orderPhone}</span>
                            <span>送达时间：{$val.orderArrivedTime}</span>
                            <span>备注信息：{$val.orderRemark}</span>
                        </div>
                    </div>
                </div>
                <div class="order-info">
                    <div class="delivery-info">
                        <div class="delivery-card ">
                            <div class="card-header nick-selected">
                                <div class="round">
                                </div>
                                <div class="line-through ">
                                </div>
                            </div>
                            <div class="card-body ">
                                <div class="status-msg">
                                    订单提交成功
                                </div>
                                <div class="prompt"> 订单号：{$val.orderId}
                                </div>
                                <div class="time">
                                      {getDate01($val.orderTime)}
                                            <!--//计算15分钟是否支付-->
                                            {if $val.paymethod neq 2 && $val.pay eq 0 && $val.received  eq 0}
                                                {$nowTime=time()}
                                                {$dis=$nowTime-$val.orderTime}
                                                {if $dis>15*60}
                                                   {autocancel($val.username,$val.orderId)}
                                                   {$val.received=4}
                                                 {/if}
                                               {/if}
                                </div>
                            </div>
                        </div>
                        <div class="delivery-card ">
                            <div class="card-header nick-selected">
                                <div class="round">
                                </div>
                                {if $val.received neq 0}
                                <div class=line-through></div>
                                {/if}
                        </div>
                        <div class="card-body ">
                            <div class="status-msg">

                                            {if $val.paymethod eq 2}
                                                  已提交订单
                                            {else}

                                                {if $val.pay eq 0}
                                                   等待支付
                                                 {else}
                                                    已支付
                                                {/if}

                                            {/if}


                            </div>
                            <div class="prompt">
                                            {if $val.paymethod eq 2}
                                                  等待商家接单
                                             {else}
                                                    {if $val.pay eq 0}
                                                    请在提交订单后15分钟内完成支付
                                                    {else}
                                                     已支付，订单进行中
                                                    {/if}
                                             {/if}

                            </div>
                            <div class="time">
                                 {if $val.pay eq 1}
                                    {if $val.payTime}
                                   {getDate01($val.payTime)}
                                     {/if}
                                 {/if}
                            </div>
                        </div>
                    </div>
                    <div
                         {if $val.received eq 0}
                         class='delivery-card n'
                          {else}
                         class='delivery-card'
                         {/if}
                        >
                    <div class="card-header nick-selected">
                        <div class="round">
                        </div>
                    </div>
                    <div class="card-body ">
                        <div class="status-msg">
                            {if $val.received eq 1}
                                  商家已接单
                             {elseif $val.received eq 2}
                                  商家拒绝接单
                             {elseif $val.received eq 3}
                                  订单完成
                             {elseif $val.received eq 4}
                                  订单取消
                             {elseif $val.received eq 5}
                                  订单取消
                            {/if}
                        </div>
                        <div class="prompt">
                            {if $val.received eq 1}
                            请您耐心等待
                            {elseif $val.received eq 2}
                            商家忙碌，无法接单
                            {elseif $val.received eq 3}
                            订单完成，欢迎下次再来
                            {elseif $val.received eq 4}
                            未支付，订单自动取消
                            {elseif $val.received eq 5}
                            用户取消订单
                            {/if}

                        </div>
                        <div class="time">
                            {if $val.received neq 0}
                                {if $val.receivedTime}
                                {getDate01($val.receivedTime)}
                                {/if}
                            {/if}
                        </div>
                    </div>
                </div>
                <div class="order-operator " >
                    <div class="operator-btns">
                        {if $val.paymethod neq 2 && $val.pay eq 0 && $val.received eq 0}
                        <a class=pay-btn onclick="orderPay({$val.username},{$val.orderId},{$val.price},{$val.orderTime},{$val.paymethod})">支付</a> <a class=pay-btn onclick="orderCancel({$val.orderId},{$val.username})">取消</a>
                          {elseif $val.paymethod eq 2 && $val.received eq 0}
                        <a class=pay-btn onclick="orderCancel({$val.orderId},{$val.username})">取消</a>
                          {elseif $val.received eq 1}
                        <a class=pay-btn onclick="urgeOrder({$val.orderId},{$val.username})">催单</a>
                          {elseif $val.received eq 3}
                        <a class="pay-btn exp">评价</a><a href='?m=home&c=Shopc&a=index&shopId={$val.shopId}' class=pay-btn>再买一次</a>
                        {/if}

                    </div>
                </div>
                <div class="clear">
                </div>
            </div>
        </div>
    </div>
   {/foreach}


        <div class="page" style="background-color: #9AA4FF">{$page}</div>
         <p align="center">
             共{$count}条数据
         </p>
    </div>
        {/if}
</div>

</div>

<div class="clear"></div>
</div>
{include file="{APP_PPDP}/home/fonter.html"}
<div class="shop-cart shadow n">
    <div class="shop-head">
        购物车<a class="shop-clear">[清空]</a>
    </div>
    <div class="shop-body">
        <div class="isnull">
            <span></span>
            <b>购物车空空如也</b>
        </div>
    </div>
    <div class="shop-bottom">
        <div class="bottom-price fl">总计：￥<label>32</label>
        </div>
        <div class="bottom-icon"></div>
        <div class="bottom-pay fr">
            <a id="cart-pay">结算</a>
        </div>
    </div>
</div>
<!--提示框-->
<div id="alertModel" class="alertModel" >
    <a id="alert" data-reveal-id="alertModel" data-animation="fade"></a>
    <span id="alert-msg"></span>
    <button id="btn-ok" class="btn">知道了</button>
    <a id="btn-close" class="close-reveal-modal"><img src="{IMAGE}home/icon_close.png" height="24" width="24"></a>
</div>

<script src="{JS}home/common.js"></script>
<script src="{JS}home/md5.js"></script>
<script src="{JS}home/login.js"></script>
<script src="{JS}home/cart.lib.js"></script>
<script src="{JS}home/cart.js"></script>
<script src="{JS}home/common.js"></script>
<script src="{JS}home/header.js"></script>
<script src="{JS}home/account.js"></script>
<script src="{JS}home/footer.js"></script>
<script type="text/javascript">
    $(function(){
        //初始化购物车
        initCart();

        //footer
        processFooter();

        //地址悬浮
        $(".place-cc a,.place-nav").hover(function() {
            $('.place-nav').show();
        }, function() {
            $('.place-nav').hide();
        });

        //购物车相关
        var shopCartWidth=$(".shop-cart").width();
        //默认隐藏购物车
        $(".shop-cart,.shop-bottom").css("right",-shopCartWidth);
        var mRight=-shopCartWidth;

        $("#cart").click(function(){

            $('.shop-cart').show();
            //适配购物车
            processShopItem();

            shopCartWidth=$(".shop-cart").width();
            if(mRight=='0px'){
                mRight=-shopCartWidth;
                $(".shop-cart,.shop-bottom").animate({literal}{right:mRight}{/literal},200);
                }
            else{
                    mRight='0px';
                    $(".shop-cart,.shop-bottom").animate({literal}{right:mRight}{/literal},200);
                    }
                });




                //中间高
                var zw=$(window).width();
                var middleWidth=$('.place-wrap').width();
                var middleHeight=$('.place-wrap').height();
                var marginLeft=(zw-middleWidth)/2;
                $(".place-wrap-1").css("marginLeft",marginLeft);
                $(".place-wrap-1").show();

                //地址选择悬浮
                $(".place-nav").css("left",marginLeft+32);//再加32
                //地址点击
                $('.city').click(function(event) {
                    var ip=$(this).attr("ip");
                    location.href="?m=home&c=Indexc&a=index&ip="+ip;
                });

                //弹出动画
                $(".place-wrap").animate({literal}{"opacity":"0.9"}{/literal},200);




                    $(window).resize(function(){
                        //中间高
                        var zw=$(window).width();
                        var middleWidth=$('.place-wrap').width();
                        var middleHeight=$('.place-wrap').height();
                        var marginLeft=(zw-middleWidth)/2;
                        $(".place-wrap-1").css("marginLeft",marginLeft);
                        //地址选择悬浮
                        $(".place-nav").css("left",marginLeft+32);

                        //适配购物车
                        processShopItem();

                        $('.shop-cart').hide();
                        var shopCartWidth=$(".shop-cart").width();
                        //默认隐藏购物车
                        $(".shop-cart,.shop-bottom").css("right",-shopCartWidth);
                        mRight=-shopCartWidth;

                        processFooter();
                    });


                    //tab点击事件
                    $('.place-tab a').live("click",function(){
                        //变样式
                        obj=$(this);
                        var cl=obj.parents('.place-tab').find('a');
                        cl.removeClass('alive');
                        $(this).addClass('alive');
                        var pid=obj.attr('id');
                        var cityId=obj.attr('cityId');
                        var status=obj.attr('status');

                        if(status==1)
                        {
                            $.ajax({
                                type:"get",
                                url:"?m=home&c=Shopc&a=current_business&cityId="+cityId,
                                dataType:"json",
                                success:function(reg){
                                    if(reg==0)
                                    {
                                        showAlert("暂没有店铺");
                                    }else{
                                        var str="";
                                        for(var j=0;j<reg.length;j++)
                                        {
                                            str+='<div class="name-item"><a href="?m=home&c=Shopc&a=index&shopId='+reg[j]['shopId']+'">'+reg[j]['shopName']+'</a></div>';
                                        }
                                        var n="#"+pid.replace('t','n');
                                        $(n).html(str);
                                    }
                                }
                            })
                        }
                        obj.attr('status',0);
                        $('.place-names').hide();
                        var n="#"+pid.replace('t','n');
                        $(n).show();
                    });

        function processFooter(){
            var zh=$(document.body).height();
            $(".footer-content").css('top', zh-60);
            $(".footer-content").show();
        };


    });
                //取消订单
                function orderCancel(orderId,username){
                    var postUrl="?m=home&c=Orderc&a=order_Cancel";

                    $.post(postUrl,
                        {
                            orderId:orderId,
                            username:username
                        },
                        function(data,status,xhr) {
                            if(status=="success"){
                                $res= $.parseJSON(data);
                                if($res.code=="0"){
                                    showAlert("取消成功","?m=home&c=Orderc&a=order_list");
                                }else if($res.code=="1"){
                                    showAlert($res.msg,"?m=home&c=Orderc&a=order_list");
                                }
                            }else{
                                showAlert("服务器异常","?m=home&c=Orderc&a=order_list");
                            }
                        });
                }
                //支付订单。
                function orderPay(username,orderId,price,orderTime,paymethod){
                    var timestamp = Date.parse(new Date());
                    var nowTime=timestamp/1000;
                    var dis=nowTime-orderTime;
                    if(dis>15*60){
                        showAlert("超过15分钟未支付，订单已取消","?m=home&c=Orderc&a=order_list");
                    }else{
                        if(paymethod==3)
                        {
                            window.location.href=encodeURI("?m=home&c=Orderc&a=money_pay&username="+username+"&orderId="+orderId+"&price="+price+"&orderTime="+orderTime);
                        }
                        if(paymethod==1)
                        {
                            window.location.href=encodeURI("?m=home&c=Orderc&a=alipay&username="+username+"&orderId="+orderId+"&price="+price+"&orderTime="+orderTime);
                        }

                    }
                }

                //催单
                function urgeOrder(orderId,username){
                    var postUrl="?m=home&c=Orderc&a=urge_Order";
                    $.post(postUrl,
                        {
                            orderId:orderId,
                            username:username
                        },
                        function(data,status,xhr) {
                            if(status=="success"){
                                $res= $.parseJSON(data);
                                if($res.code=="0"){
                                    showAlert("已通知商家");
                                }else if($res.code=="1"){
                                    showAlert($res.msg);
                                }
                            }else{
                                showAlert("服务器异常");
                            }
                        });
                }
                $(".exp").click(function(){
                     showAlert("暂未开放");
                })

</script>
</body>
</html>